/*
 * Filename:    HcpmsPdfCellUtil.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014-12-10
 */
package com.paic.mhis.hcpms.itextpdf.web.util;

import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;

public class HcpmsPdfCellUtil {
	public static PdfPCell createCell(Paragraph p, int[] padding, int align) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		return cell;
	}

	public static PdfPCell createCell(Paragraph p, int[] padding, int align, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		if (height > 0) {
			cell.setMinimumHeight(height);
		}
		return cell;
	}

	public static PdfPCell createCell(Paragraph p, int[] padding, int align, int border, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setBorder(border);
		if (height > 0) {
			cell.setMinimumHeight(height);
		}
		return cell;
	}

	public static PdfPCell createCell(Paragraph p, int[] padding, int align, int border) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setBorder(border);
		return cell;
	}

	public static PdfPCell createCellRow(Paragraph p, int[] padding, int align, int row) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setRowspan(row);
		return cell;
	}

	public static PdfPCell createCellRow(Paragraph p, int[] padding, int align, int row, int border) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setRowspan(row);
		cell.setBorder(border);
		return cell;
	}

	public static PdfPCell createCellRow(Paragraph p, int[] padding, int align, int row, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setRowspan(row);
		if (height > 0) {
			cell.setMinimumHeight(height);
		}
		return cell;
	}

	public static PdfPCell createCellRow(Paragraph p, int[] padding, int align, int row, int border, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setRowspan(row);
		cell.setBorder(border);
		if (height > 0) {
			cell.setMinimumHeight(height);
		}
		return cell;
	}

	public static PdfPCell createCellCol(Paragraph p, int[] padding, int align, int cols) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setColspan(cols);
		return cell;
	}

	public static PdfPCell createCellCol(Paragraph p, int[] padding, int align, int cols, int border) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setColspan(cols);
		cell.setBorder(border);
		return cell;
	}

	public static PdfPCell createCellCol(Paragraph p, int[] padding, int align, int cols, int border, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setColspan(cols);
		cell.setBorder(border);
		if (height > 0) {
			cell.setMinimumHeight(height);
		}
		return cell;
	}

	public static PdfPCell createCellCol(Paragraph p, int[] padding, int align, int cols, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setColspan(cols);
		cell.setMinimumHeight(height);
		return cell;
	}

	public static PdfPCell createCell(Paragraph p, int align) {
		PdfPCell cell = createCellAndSetPadding(p, null);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		return cell;
	}

	public static PdfPCell createCellPadding(Paragraph p, int align, int[] padding) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		return cell;
	}

	public static PdfPCell createCellCenterRow(Paragraph p, int align, int row) {
		PdfPCell cell = createCellAndSetPadding(p, null);
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(align);
		cell.setRowspan(row);
		return cell;
	}

	public static PdfPCell createCellCenter(Paragraph p, int align) {
		PdfPCell cell = createCellAndSetPadding(p, null);
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(align);
		return cell;
	}

	public static PdfPCell createCellCenter(Paragraph p, int[] padding, int align, float height) {
		PdfPCell cell = createCellAndSetPadding(p, padding);
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(align);
		if (height > 0) {
			cell.setMinimumHeight(height);
		}
		return cell;
	}

	public static PdfPCell createCellRow(Paragraph p, int alignCenter, int row) {
		PdfPCell cell = createCellAndSetPadding(p, null);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(alignCenter);
		cell.setRowspan(row);
		return cell;
	}

	public static PdfPCell createCellMiddle(Paragraph p, int align) {
		PdfPCell cell = createCellAndSetPadding(p, null);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		return cell;
	}

	public static PdfPCell createCellAndSetPadding(Paragraph p, int[] padding) {
		if (p == null) {
			p = new Paragraph("");
		}
		PdfPCell cell = new PdfPCell(p);
		if (padding == null) {
		} else {
			if (padding.length > 0) {
				cell.setPaddingTop(padding[0]);
			}
			if (padding.length > 1) {
				cell.setPaddingRight(padding[1]);
			}
			if (padding.length > 2) {
				cell.setPaddingBottom(padding[2]);
			}
			if (padding.length > 3) {
				cell.setPaddingLeft(padding[3]);
			}
		}
		cell.setNoWrap(false);
		cell.setUseAscender(true);
		cell.setUseBorderPadding(true);
		cell.setUseDescender(true);
		return cell;
	}
}
